/*
 * 表单
 */

Ext.define("NotesApp.view.NoteEditor", {
	extend: "Ext.form.Panel",
	requires: "Ext.form.FieldSet",
	alias: "widget.noteeditor",
	config: {
		scrollable: 'vertical'
	},
	initialize: function() {

		this.callParent(arguments);

		// 返回
		var backButton = {
			xtype: "button",
			ui: "back",
			text: "返回",
			handler: this.onBackButtonTap,
    			scope: this
		};

		// 保存
		var saveButton = {
			xtype: "button",
			ui: "action",
			text: "保存",
			handler: this.onSaveButtonTap,
    			scope: this
		};

		// 上边栏
		var topToolbar = {
			xtype: "toolbar",
			docked: "top",
			title: "Edit Note",
			items: [
				backButton, {
					xtype: "spacer"
				},
				saveButton
			]
		};

		// 删除
		var deleteButton = {
		    xtype: "button",
		    iconCls: "trash",
		    iconMask: true,
		    handler: this.onDeleteButtonTap,
		    scope: this
		}

		// 下边栏
		var bottomToolbar = {
			xtype: "toolbar",
			docked: "bottom",
			items: [
				deleteButton
			]
		};

		// 标题textField
		var noteTitleEditor = {
			xtype: 'textfield',
			name: 'title',	// 数据模型的name
			label: '名称',
			required: true
		};

		// 描述textField
		var noteNarrativeEditor = {
			xtype: 'textareafield',
			name: 'narrative', // 数据模型的name
			label: '描述'
		};

		this.add([
			topToolbar, {
				xtype: "fieldset",
				items: [noteTitleEditor, noteNarrativeEditor]
			},
			bottomToolbar
		]);
	},
	
	onSaveButtonTap : function(){
		
		console.log("点击了 保存");
		this.fireEvent('saveNoteCommand', this);
	},
	
	onBackButtonTap	: function () {
		
   	 	console.log("点击了 返回");
    		this.fireEvent("backToHomeCommand", this);
	},

	onDeleteButtonTap: function () {
	    console.log("点击了 删除");
	    this.fireEvent("deleteNoteCommand", this);
	}



});